clear all
cd "C:\Users\ot3\Documents\TeacherDeseg\OCRandSERS"


*Figure 1: Trends
use teachers_8state, clear	
replace black_stud_dscnt=black_stud_cnt*frac_stud_deseg if year<=1964

g sdeseg=black_stud_dscnt/ black_stud_cnt
g btshare=black_teach_cnt/( black_teach_cnt+ white_teach_cnt)

collapse (mean) frac_stud_black sdeseg btshare, by(year)

twoway connect sdeseg year , lpattern(solid) lcolor(black) lwidth(medthick) mcolor(black) msymbol(square)  || connect btshare year , yaxis(2) lpattern(dash) lwidth(medium) lcolor(gs7) mcolor(gs7) msymbol(circle) ///
legend(label(1 "Student Desegregation (left axis)")  label(2 "Black Teacher Share (right axis)") rows(2)) ///
subtitle(Figure 1: Trends in Student Desegregation and Black Teacher Employment) xtitle(Year) ytitle(Student Desegregation Share) ytitle(Black Teacher Share, axis(2))  /// 
xtick(1960 (2) 1972) xlabel(1960 (2) 1972) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) 


	 
*Correlation quoted in Appendix A theoretical model
use teachers_8state, clear
corr frac_teach_black frac_stud_black if year==1964 [aweight=stud_cnt]



*Table 1: Main Results
use teachers_8state, clear	

*base
qui areg lblackteach frac_stud_deseg   i.year , abs(distcode) cluster(distcode)
est sto base
di 1-exp(_b[frac_stud_deseg])

*linear district trends
qui areg lblackteach frac_stud_deseg  i.year c.year#distcode , abs(distcode) cluster(distcode) 
est sto ctrends
di 1-exp(_b[frac_stud_deseg])

*year-by-district characteristic interactions
qui areg lblackteach frac_stud_deseg   OCRstate##year c.bshare1964##year c.stud_cnt1964##year, abs(distcode) cluster(distcode) 
est sto YxDtrends

*policy controls 
qui areg lblackteach frac_stud_deseg  i.year  /*revfed revst revloc*/ hsfund tranpcmcare tranpcmcaid tranpcfsp tranpcafdc tranpcssi tranpcga  , abs(distcode) cluster(distcode) 
est sto policyconts

*with controls
qui areg lblackteach frac_stud_deseg  lteach frac_stud_black   i.year, abs(distcode) cluster(distcode)
est sto withconts
di 1-exp(_b[frac_stud_deseg])

*weighted
replace black_teach_cnt1964=black_teach_cnt1964+1 //to preserve 4 districts with no black teachers in 1964, but positive number in other years from 1960-1964
qui areg lblackteach frac_stud_deseg   i.year [pweight=black_teach_cnt1964], abs(distcode) cluster(distcode)
est sto weighted

di 1-exp(_b[frac_stud_deseg])
egen totbt=total(black_teach_cnt) if year==1964
g totch=totbt*(1-exp(_b[frac_stud_deseg]))


outreg2 [*] using T1,  keep(frac_stud_deseg   lteach frac_stud_black ) dec(3)  nocons nor2 replace




*Figure 2: Trimmed Event Study
*Identify period-to-period changes greater than .50, generate event time
use teachers_8state, clear
sort distcode year
bysort distcode: egen lineartime=seq()
xtset distcode lineartime

g desegL1=L.frac_stud_deseg
g deseg_change=frac_stud_deseg-desegL1
g event=deseg_change>.50 & deseg_change!=.

bysort distcode: egen maxdeseg=max(frac_stud_deseg)
bysort distcode: egen maxchange=max(deseg_change)
bysort distcode: egen anyevent=sum(event) //technically summing number of events, to be able to exclude multi-event districts
drop if anyevent==2 //three districts had increase, then decrease, then increase again. Drop them. 
keep if anyevent==1  | (maxchange<.20 & maxdeseg<.4)

g eyear=lineartime if event==1
bysort distcode: egen eventyear=max(eyear)
drop if eventyear==9 //drop events occuring in 1972, so I can see one lag
g etime=lineartime-eventyear

replace etime=-1 if anyevent==0 //code event time as -1 for untreated units

keep if etime>=-5 & etime<=1 //"trimming" to balanced panel

tab etime, gen(ET)

areg lblackteach frac_stud_deseg   i.year , abs(distcode) cluster(distcode)

areg lblackteach ET1 ET2 ET3 ET4  ET6 ET7 i.lineartime , abs(distcode)  cluster(distcode) 
matrix res=[	-5, _b[ET1], _se[ET1] \ -4, _b[ET2], _se[ET2]  \ -3, _b[ET3], _se[ET3]  \ -2, _b[ET4], _se[ET4] \ -1, 0, 0 \ 0, _b[ET6], _se[ET6]  \ 1, _b[ET7], _se[ET7] ]

svmat res
keep res*
keep in 1/7
rename res1 etime
rename res2 beta
rename res3 se
g min=beta-1.96*se
g max=beta+1.96*se

g baseline=1
save Fig2data, replace




*A&S Correction
*Identify period-to-period changes greater than .50, generate event time
use teachers_8state, clear	
sort distcode year
bysort distcode: egen lineartime=seq()
xtset distcode lineartime

g desegL1=L.frac_stud_deseg
g deseg_change=frac_stud_deseg-desegL1
g event=deseg_change>.50 & deseg_change!=.

bysort distcode: egen maxdeseg=max(frac_stud_deseg)
bysort distcode: egen maxchange=max(deseg_change)
bysort distcode: egen anyevent=sum(event) //technically summing number of events, to be able to exclude multi-event districts
drop if anyevent==2 //three districts had increase, then decrease, then increase again. Drop them. 
keep if anyevent==1  | (maxchange<.20 & maxdeseg<.4)

g eyear=lineartime if event==1
bysort distcode: egen eventyear=max(eyear)
drop if eventyear==9 //drop events occuring in 1972, so I can see one lag
g etime=lineartime-eventyear

replace etime=-1 if anyevent==0 //code event time as -1 for untreated units

keep if etime>=-5 & etime<=1 //"trimming" to balanced panel

tab etime, gen(ET)


*estimate the CATT 
levelsof eventyear, local(cohorts)
foreach c of numlist 6 7 8 {
foreach t of numlist 1/7 {
g ET`t'_cohort`c'=ET`t'==1 & eventyear==`c'
}
}
areg lblackteach ET1_cohort6 ET1_cohort7 ET1_cohort8 ET2_cohort6 ET2_cohort7 ET2_cohort8 ET3_cohort6 ET3_cohort7 ET3_cohort8 ET4_cohort6 ET4_cohort7 ET4_cohort8 ET6_cohort6 ET6_cohort7 ET6_cohort8 ET7_cohort6 ET7_cohort7 ET7_cohort8 i.lineartime, abs(distcode)  cluster(distcode) 


*Calculate the weights, which are just the cohort shares since I trimmed to be balanced in event time
count if eventyear == 6 & lineartime==4
local c6 = r(N)
count if eventyear == 7 & lineartime==4
local c7 = r(N)
count if eventyear == 8 & lineartime==4
local c8 = r(N)

local w6=`c6'/ (`c6'+`c7'+`c8')
local w7=`c7'/(`c6'+`c7'+`c8')
local w8=`c8'/(`c6'+`c7'+`c8')

di `w6' `w7' `w8'

*Take average each event time coefficient across the three cohorts, weighted by their shares
foreach n of numlist 1/4 6/7 {
lincom _b[ET`n'_cohort6]*`w6' + _b[ET`n'_cohort7]*`w7' + _b[ET`n'_cohort8]*`w8'
local beta`n'=`r(estimate)'
local se`n'=`r(se)'
}

matrix res=[-5, `beta1', `se1' \ -4, `beta2', `se2'  \ -3, `beta3', `se3'  \ -2, `beta4', `se4'  \ -1, 0, 0 \ 0, `beta6', `se6'   \ 1, `beta7', `se7'  ]


*Make figure
svmat res
keep res*
keep in 1/7
rename res1 etime
rename res2 beta
rename res3 se

g min=beta-1.96*se
g max=beta+1.96*se

g baseline=0
append using Fig2data

twoway connect beta etime if baseline==0, lpattern(dash) lcolor(gs10)  mcolor(gs10)  msymbol(s) msize(small)  ///
|| rcap min max etime if baseline==0,  lcolor(gs10) lwidth(thin) ///
|| connect beta etime if baseline==1, lpattern(solid) lcolor(black)  mcolor(black)  msymbol(circle) msize(small)  ///
|| rcap min max etime if baseline==1,  lcolor(black) lwidth(thin) ///
xline(-1, lcolor(black) ) ///
legend(order(3 1)  label(3 "Baseline Event-Study Coefficients")  label(1 "Sun & Abraham (2020) Correction") rows(2)) ///
xtitle(Event-Time) ytitle("Log Black Teacher Employment") xtick(-5(1)1) xlabel(-5(1)1) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) ///
subtitle("Figure 2: Event Study Results") 





*Appendix Table A4: CATTs and weights
use teachers_8state, clear	
sort distcode year
bysort distcode: egen lineartime=seq()
xtset distcode lineartime
g desegL1=L.frac_stud_deseg
g deseg_change=frac_stud_deseg-desegL1
g event=deseg_change>.50 & deseg_change!=.
bysort distcode: egen maxdeseg=max(frac_stud_deseg)
bysort distcode: egen maxchange=max(deseg_change)
bysort distcode: egen anyevent=sum(event) 
drop if anyevent==2 
keep if anyevent==1  | (maxchange<.20 & maxdeseg<.4)

g eyear=lineartime if event==1
bysort distcode: egen eventyear=max(eyear)
drop if eventyear==9 
g etime=lineartime-eventyear

replace etime=-1 if anyevent==0 
keep if etime>=-5 & etime<=1 //"trimming" to balanced panel
tab etime, gen(ET)

areg lblackteach ET1 ET2 ET3 ET4  ET6 ET7 i.lineartime, abs(distcode)  cluster(distcode) 
est sto base

areg lblackteach ET1 ET2 ET3 ET4  ET6 ET7 i.lineartime if eventyear==6 | anyevent==0, abs(distcode)  cluster(distcode) 
est sto coh1967

areg lblackteach ET1 ET2 ET3 ET4  ET6 ET7 i.lineartime if eventyear==7 | anyevent==0, abs(distcode)  cluster(distcode) 
est sto coh1968

areg lblackteach ET1 ET2 ET3 ET4  ET6 ET7 i.lineartime if eventyear==8 | anyevent==0, abs(distcode)  cluster(distcode) 
est sto coh1970

outreg2 [*] using TA4,   dec(3)  keep(ET1 ET2 ET3 ET4  ET6 ET7) nocons nor2  replace







*Appendix Figure A2: Binned Event Study
use teachers_8state, clear	
sort distcode year
bysort distcode: egen lineartime=seq()
xtset distcode lineartime
g desegL1=L.frac_stud_deseg
g deseg_change=frac_stud_deseg-desegL1
g event=deseg_change>.50 & deseg_change!=.
bysort distcode: egen maxdeseg=max(frac_stud_deseg)
bysort distcode: egen maxchange=max(deseg_change)
bysort distcode: egen anyevent=sum(event) 
drop if anyevent==2 
keep if anyevent==1  | (maxchange<.20 & maxdeseg<.4)

g eyear=lineartime if event==1
bysort distcode: egen eventyear=max(eyear)
drop if eventyear==9 
g etime=lineartime-eventyear

replace etime=-1 if anyevent==0 

*bin endpoints
replace etime=-6 if etime<-6
replace etime=2 if etime>2

tab etime, gen(ET)

areg lblackteach ET1 ET2 ET3 ET4  ET5 ET7 ET8 ET9 i.lineartime, abs(distcode)  cluster(distcode)  
matrix res=[	-5, _b[ET2], _se[ET2] \ -4, _b[ET3], _se[ET3]  \ -3, _b[ET4], _se[ET4]  \ -2, _b[ET5], _se[ET5] \ -1, 0, 0 \ 0, _b[ET7], _se[ET7]  \ 1, _b[ET8], _se[ET8] ]


*Make figure
svmat res
keep res*
keep in 1/7
rename res1 etime
rename res2 beta
rename res3 se
g min=beta-1.96*se
g max=beta+1.96*se

g baseline=1
save FigA2data, replace


*A&S Correction	
use teachers_8state, clear
sort distcode year
bysort distcode: egen lineartime=seq()
xtset distcode lineartime
g desegL1=L.frac_stud_deseg
g deseg_change=frac_stud_deseg-desegL1
g event=deseg_change>.50 & deseg_change!=.
bysort distcode: egen maxdeseg=max(frac_stud_deseg)
bysort distcode: egen maxchange=max(deseg_change)
bysort distcode: egen anyevent=sum(event) 
drop if anyevent==2 
keep if anyevent==1  | (maxchange<.20 & maxdeseg<.4)

g eyear=lineartime if event==1
bysort distcode: egen eventyear=max(eyear)
drop if eventyear==9 
g etime=lineartime-eventyear

replace etime=-1 if anyevent==0 

*bin endpoints
replace etime=-6 if etime<-6
replace etime=2 if etime>2

tab etime, gen(ET)

*estimate the CATT 
levelsof eventyear, local(cohorts)
foreach c of numlist 6 7 8 {
foreach t of numlist 1/9 {
g ET`t'_cohort`c'=ET`t'==1 & eventyear==`c'
}
}
areg lblackteach ET1_cohort6 ET1_cohort7 ET1_cohort8 ET2_cohort6 ET2_cohort7 ET2_cohort8 ET3_cohort6 ET3_cohort7 ET3_cohort8 ET4_cohort6 ET4_cohort7 ET4_cohort8 ET5_cohort6 ET5_cohort7 ET5_cohort8 ET7_cohort6 ET7_cohort7 ET7_cohort8 ET8_cohort6 ET8_cohort7 ET8_cohort8 ET9_cohort6 ET9_cohort7 ET9_cohort8 i.lineartime, abs(distcode)  cluster(distcode) 


*Calculate the weights
count if eventyear == 6 & lineartime==4
local c6 = r(N)
count if eventyear == 7 & lineartime==4
local c7 = r(N)
count if eventyear == 8 & lineartime==4
local c8 = r(N)

local w6=`c6'/ (`c6'+`c7'+`c8')
local w7=`c7'/(`c6'+`c7'+`c8')
local w8=`c8'/(`c6'+`c7'+`c8')

foreach n of numlist 2/5 7/8 {
lincom _b[ET`n'_cohort6]*`w6' + _b[ET`n'_cohort7]*`w7' + _b[ET`n'_cohort8]*`w8'
local beta`n'=`r(estimate)'
local se`n'=`r(se)'
}

matrix res=[-5, `beta2', `se2' \ -4, `beta3', `se3'  \ -3, `beta4', `se4'  \ -2, `beta5', `se5'  \ -1, 0, 0 \ 0, `beta7', `se7'   \ 1, `beta8', `se8'  ]


*Make figure
svmat res
keep res*
keep in 1/7
rename res1 etime
rename res2 beta
rename res3 se

g min=beta-1.96*se
g max=beta+1.96*se

g baseline=0
append using FigA2data

twoway connect beta etime if baseline==0, lpattern(dash) lcolor(gs10)  mcolor(gs10)  msymbol(s) msize(small)  ///
|| rcap min max etime if baseline==0,  lcolor(gs10) lwidth(thin) ///
|| connect beta etime if baseline==1, lpattern(solid) lcolor(black)  mcolor(black)  msymbol(circle) msize(small)  ///
|| rcap min max etime if baseline==1,  lcolor(black) lwidth(thin) ///
xline(-1, lcolor(black) ) ///
legend(order(3 1)  label(3 "Baseline Event-Study Coefficients")  label(1 "Sun & Abraham (2020) Correction") rows(2)) ///
xtitle(Event-Time) ytitle("Log Black Teacher Employment") xtick(-5(1)1) xlabel(-5(1)1) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) ///
title("Figure A2: Binned Event Study Results", size(medium)) 







*Appendix Figure A3: Keeping districts with 1972 event-times
use teachers_8state, clear	
sort distcode year
bysort distcode: egen lineartime=seq()
xtset distcode lineartime
g desegL1=L.frac_stud_deseg
g deseg_change=frac_stud_deseg-desegL1
g event=deseg_change>.50 & deseg_change!=.
bysort distcode: egen maxdeseg=max(frac_stud_deseg)
bysort distcode: egen maxchange=max(deseg_change)
bysort distcode: egen anyevent=sum(event) 
drop if anyevent==2 
keep if anyevent==1  | (maxchange<.20 & maxdeseg<.4)

g eyear=lineartime if event==1
bysort distcode: egen eventyear=max(eyear)
g etime=lineartime-eventyear

replace etime=-1 if anyevent==0 
keep if etime>=-5 & etime<=0 
tab etime, gen(ET)

areg lblackteach ET1 ET2 ET3 ET4  ET6  i.lineartime, abs(distcode)  cluster(distcode) 
matrix res=[	-5, _b[ET1], _se[ET1] \ -4, _b[ET2], _se[ET2]  \ -3, _b[ET3], _se[ET3]  \ -2, _b[ET4], _se[ET4] \ -1, 0, 0 \ 0, _b[ET6], _se[ET6]  ]


*Make figure
svmat res
keep res*
keep in 1/7
rename res1 etime
rename res2 beta
rename res3 se
g min=beta-1.96*se
g max=beta+1.96*se

g baseline=1
save FigA3data, replace



*A&S Correction
use teachers_8state, clear	
sort distcode year
bysort distcode: egen lineartime=seq()
xtset distcode lineartime
g desegL1=L.frac_stud_deseg
g deseg_change=frac_stud_deseg-desegL1
g event=deseg_change>.50 & deseg_change!=.
bysort distcode: egen maxdeseg=max(frac_stud_deseg)
bysort distcode: egen maxchange=max(deseg_change)
bysort distcode: egen anyevent=sum(event) 
drop if anyevent==2 
keep if anyevent==1  | (maxchange<.20 & maxdeseg<.4)

g eyear=lineartime if event==1
bysort distcode: egen eventyear=max(eyear)
g etime=lineartime-eventyear

replace etime=-1 if anyevent==0 
keep if etime>=-5 & etime<=0
tab etime, gen(ET)

areg lblackteach ET1 ET2 ET3 ET4  ET6  i.lineartime , abs(distcode)  cluster(distcode) 


levelsof eventyear, local(cohorts)
foreach c of numlist 6 7 8 {
foreach t of numlist 1/6 {
g ET`t'_cohort`c'=ET`t'==1 & eventyear==`c'
}
}
areg lblackteach ET1_cohort6 ET1_cohort7 ET1_cohort8 ET2_cohort6 ET2_cohort7 ET2_cohort8 ET3_cohort6 ET3_cohort7 ET3_cohort8 ET4_cohort6 ET4_cohort7 ET4_cohort8 ET6_cohort6 ET6_cohort7 ET6_cohort8  i.lineartime, abs(distcode)  cluster(distcode) 

count if eventyear == 6 & lineartime==4
local c6 = r(N)
count if eventyear == 7 & lineartime==4
local c7 = r(N)
count if eventyear == 8 & lineartime==4
local c8 = r(N)

local w6=`c6'/ (`c6'+`c7'+`c8')
local w7=`c7'/(`c6'+`c7'+`c8')
local w8=`c8'/(`c6'+`c7'+`c8')

foreach n of numlist 1/4 6 {
lincom _b[ET`n'_cohort6]*`w6' + _b[ET`n'_cohort7]*`w7' + _b[ET`n'_cohort8]*`w8'
local beta`n'=`r(estimate)'
local se`n'=`r(se)'
}

matrix res=[-5, `beta1', `se1' \ -4, `beta2', `se2'  \ -3, `beta3', `se3'  \ -2, `beta4', `se4'  \ -1, 0, 0 \ 0, `beta6', `se6'   ]


*Make figure
svmat res
keep res*
keep in 1/7
rename res1 etime
rename res2 beta
rename res3 se

g min=beta-1.96*se
g max=beta+1.96*se

g baseline=0
append using FigA3data

twoway connect beta etime if baseline==0, lpattern(dash) lcolor(gs10)  mcolor(gs10)  msymbol(s) msize(small)  ///
|| rcap min max etime if baseline==0,  lcolor(gs10) lwidth(thin) ///
|| connect beta etime if baseline==1, lpattern(solid) lcolor(black)  mcolor(black)  msymbol(circle) msize(small)  ///
|| rcap min max etime if baseline==1,  lcolor(black) lwidth(thin) ///
xline(-1, lcolor(black) ) ///
legend(order(3 1)  label(3 "Baseline Event-Study Coefficients")  label(1 "Sun & Abraham (2020) Correction") rows(2)) ///
xtitle(Event-Time) ytitle("Log Black Teacher Employment") xtick(-5(1)0) xlabel(-5(1)0) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) ///
title("Figure A3: Districts with Events in 1972 Included", size(medium))





*Appendix Figure A4: With untreated units excluded
use teachers_8state, clear	
sort distcode year
bysort distcode: egen lineartime=seq()
xtset distcode lineartime
g desegL1=L.frac_stud_deseg
g deseg_change=frac_stud_deseg-desegL1
g event=deseg_change>.50 & deseg_change!=.
bysort distcode: egen maxdeseg=max(frac_stud_deseg)
bysort distcode: egen maxchange=max(deseg_change)
bysort distcode: egen anyevent=sum(event) 
drop if anyevent==2 
keep if anyevent==1  

g eyear=lineartime if event==1
bysort distcode: egen eventyear=max(eyear)
drop if eventyear==9 
g etime=lineartime-eventyear

replace etime=-1 if anyevent==0 
keep if etime>=-5 & etime<=1 
tab etime, gen(ET)

areg lblackteach ET1 ET2 ET3 ET4  ET6 ET7 i.lineartime, abs(distcode)  cluster(distcode) 
matrix res=[	-5, _b[ET1], _se[ET1] \ -4, _b[ET2], _se[ET2]  \ -3, _b[ET3], _se[ET3]  \ -2, _b[ET4], _se[ET4] \ -1, 0, 0 \ 0, _b[ET6], _se[ET6]  \ 1, _b[ET7], _se[ET7] ]

areg lblackteach frac_stud_deseg   i.year , abs(distcode) cluster(distcode)

svmat res
keep res*
keep in 1/7
rename res1 etime
rename res2 beta
rename res3 se
g min=beta-1.96*se
g max=beta+1.96*se

g baseline=1
save NoUntreated, replace


*A&S Correction 
use teachers_8state, clear	
set matsize 10000
sort distcode year
bysort distcode: egen lineartime=seq()
xtset distcode lineartime
g desegL1=L.frac_stud_deseg
g deseg_change=frac_stud_deseg-desegL1
g event=deseg_change>.50 & deseg_change!=.
bysort distcode: egen maxdeseg=max(frac_stud_deseg)
bysort distcode: egen maxchange=max(deseg_change)
bysort distcode: egen anyevent=sum(event) 
drop if anyevent==2  
keep if anyevent==1  

g eyear=lineartime if event==1
bysort distcode: egen eventyear=max(eyear)
drop if eventyear==9 
g etime=lineartime-eventyear

keep if etime>=-5 & etime<=1 
drop if year>=1970 
tab etime, gen(ET)

levelsof eventyear, local(cohorts)
foreach c of numlist 6 7  {
foreach t of numlist 1/7 {
g ET`t'_cohort`c'=ET`t'==1 & eventyear==`c'
}
}
areg lblackteach ET1_cohort6 ET1_cohort7  ET2_cohort6 ET2_cohort7  ET3_cohort6 ET3_cohort7  ET4_cohort6 ET4_cohort7  ET6_cohort6 ET6_cohort7  ET7_cohort6 ET7_cohort7  i.lineartime, abs(distcode)  cluster(distcode) 


count if eventyear == 6 & lineartime==4
local c6 = r(N)
count if eventyear == 7 & lineartime==4
local c7 = r(N)

local w6=`c6'/ (`c6'+`c7')
local w7=`c7'/(`c6'+`c7')

foreach n of numlist 1/4 6/7 {
lincom _b[ET`n'_cohort6]*`w6' + _b[ET`n'_cohort7]*`w7' 
local beta`n'=`r(estimate)'
local se`n'=`r(se)'
}

matrix res=[-5, `beta1', `se1' \ -4, `beta2', `se2'  \ -3, `beta3', `se3'  \ -2, `beta4', `se4'  \ -1, 0, 0 \ 0, `beta6', `se6'   \ 1, `beta7', `se7'  ]


*Make figure
svmat res
keep res*
keep in 1/7
rename res1 etime
rename res2 beta
rename res3 se

g min=beta-1.96*se
g max=beta+1.96*se

g baseline=0
append using NoUntreated

twoway connect beta etime if baseline==0, lpattern(dash) lcolor(gs10)  mcolor(gs10)  msymbol(s) msize(small)  ///
|| rcap min max etime if baseline==0,  lcolor(gs10) lwidth(thin) ///
|| connect beta etime if baseline==1, lpattern(solid) lcolor(black)  mcolor(black)  msymbol(circle) msize(small)  ///
|| rcap min max etime if baseline==1,  lcolor(black) lwidth(thin) ///
xline(-1, lcolor(black) ) ///
legend(order(3 1)  label(3 "Baseline Event-Study Coefficients")  label(1 "Sun & Abraham (2020) Correction") rows(2)) ///
xtitle(Event-Time) ytitle("Log Black Teacher Employment") xtick(-5(1)1) xlabel(-5(1)1) ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) ///
title("Figure A4: Event Study Results Excluding Never-Treated Units", size(medium)) 






*Table 2: Scale of Operations
use teachers_8state, clear	

areg lteach frac_stud_deseg  i.year , abs(distcode) cluster(distcode)
est sto logallteacher

sum teach_cnt if e(sample)==1 & year==1964
sum black_teach_cnt if e(sample)==1 & year==1964

areg lstud_cnt frac_stud_deseg  i.year , abs(distcode) cluster(distcode)
est sto logstud

areg lstratio frac_stud_deseg  i.year , abs(distcode) cluster(distcode)
est sto logstratio

areg lschool_cnt frac_stud_deseg  i.year , abs(distcode) cluster(distcode)
est sto logschools
di 1-exp(_b[frac_stud_deseg])

outreg2 [*] using T1,  keep(frac_stud_deseg )  dec(3)  nocons nor2 replace 

*Other results quoted in text
areg lwhiteteach frac_stud_deseg  i.year , abs(distcode) cluster(distcode)

g frac_stud_white=1-frac_stud_black
tabstat frac_stud_white if e(sample)==1, by(year)








*Table A2:Descriptives
*8-state
clear*
use teachers_8state, clear	
areg lblackteach frac_stud_deseg   i.year , abs(distcode) cluster(distcode)
keep if e(sample)==1

keep teach_cnt black_teach_cnt white_teach_cnt stud_cnt black_stud_cnt white_stud_cnt 
order teach_cnt black_teach_cnt white_teach_cnt stud_cnt black_stud_cnt white_stud_cnt 
outreg2 using T1, sum(detail)  eqkeep(mean sd p10 p90) dec(0) replace see

clear*
use teachers_8state, clear	
qui areg lblackteach frac_stud_deseg   i.year , abs(distcode) cluster(distcode)
keep if e(sample)==1

g AL= OCRstate==1  
g AR= OCRstate==4  
g FL= OCRstate==10
g GA= OCRstate==11  
g LA= OCRstate==19  
g MS= OCRstate==25  
g NC= OCRstate==34
g SC= OCRstate==41  
g TN= OCRstate==43  
g TX= OCRstate==44 
g VA= OCRstate==47 

keep AL AR FL GA LA MS NC SC TN TX VA 
outreg2 using T1, sum(detail)  eqkeep(mean sd ) dec(3) replace see



*11-state
use teachers_11state, clear
areg lblackteach frac_stud_deseg i.year, abs(distcode) cluster(distcode)
keep if e(sample)==1

keep teach_cnt black_teach_cnt white_teach_cnt stud_cnt black_stud_cnt white_stud_cnt 
order teach_cnt black_teach_cnt white_teach_cnt stud_cnt black_stud_cnt white_stud_cnt 
outreg2 using T1, sum(detail)  eqkeep(mean sd p10 p90) dec(0) replace see


use teachers_11state, clear
areg lblackteach frac_stud_deseg i.year, abs(distcode) cluster(distcode)
keep if e(sample)==1

g AL= OCRstate==1  
g AR= OCRstate==4  
g FL= OCRstate==10
g GA= OCRstate==11  
g LA= OCRstate==19  
g MS= OCRstate==25  
g NC= OCRstate==34
g SC= OCRstate==41  
g TN= OCRstate==43  
g TX= OCRstate==44 
g VA= OCRstate==47 

keep AL AR FL GA LA MS NC SC TN TX VA
outreg2 using T1, sum(detail)  eqkeep(mean sd ) dec(3) replace see




*Table A3: Robustness
***alt sample, dep vars***
use teachers_8state, clear

*keep base estimation sample
areg lblackteach frac_stud_deseg i.year , abs(distcode) cluster(distcode)
keep if e(sample)==1

 areg lblackteach frac_stud_deseg  i.year if zero_black_teach!=1, abs(distcode) cluster(distcode)
est sto smallsample


 areg frac_teach_black frac_stud_deseg  i.year, abs(distcode) cluster(distcode)
sum frac_teach_black if e(sample)==1 & year==1964
est sto fractdepvar

 areg black_teach_cnt frac_stud_deseg  i.year, abs(distcode) cluster(distcode)
sum black_teach_cnt if e(sample)==1 & year==1964
est sto countdepvar

outreg2 [*] using T1,  keep(frac_stud_deseg )  dec(3)  nocons nor2 replace



***Negative binomial***
use teachers_8state, clear
replace black_teach_cnt=round(black_teach_cnt) //round a few full-time-equivilent teacher counts to whole numbers

xtset distcode year

xtnbreg black_teach_cnt frac_stud_deseg   i.year ,  fe vce(boot, reps(400) seed(9999))
est sto xtnb

outreg2 [*] using T1,  keep(frac_stud_deseg frac_stud_black teach_cnt)  dec(3)  nocons nor2 replace
 
 
 
***eleven state sample***
clear all
use teachers_11state
areg lblackteach frac_stud_deseg i.year, abs(distcode) cluster(distcode)
est sto elevenstate
outreg2 [*] using T1,  keep(frac_stud_deseg  )  dec(3)  nocons nor2 replace

*numbers quoted in text
keep if e(sample)==1
duplicates drop distcode, force
count
use teachers_8state, clear
areg lblackteach frac_stud_deseg  i.year if year>=1967, abs(distcode) cluster(distcode)



 
***no re-oranizations***
use teachers_8state, clear
drop if OCRstate==44 //Casico et al do not have merger data for Texas. 
areg lblackteach frac_stud_deseg  i.year if  noreorg==1, abs(distcode) cluster(distcode) 
est sto noreorgs
outreg2 [*] using T1,  keep(frac_stud_deseg  )  dec(3)  nocons nor2 replace

keep if e(sample)==1
duplicates drop distcode, force
count

***county level results***
use teachers_8state, clear
collapse (sum) white_stud_cnt black_stud_cnt black_stud_dscnt white_teach_cnt black_teach_cnt, by(OCRstate OCRcounty year)

g lblackteach=ln(black_teach_cnt+1)
g lteach=ln(black_teach_cnt + white_teach_cnt+1)
g frac_stud_black=black_stud_cnt/(black_stud_cnt+white_stud_cnt)
g frac_stud_deseg=black_stud_dscnt/black_stud_cnt

egen county=group(OCRstate OCRcounty)

areg lblackteach frac_stud_deseg  i.year, abs(county) cluster(county)
est sto county

*count number of unique counties
keep if e(sample)==1
duplicates drop county, force
count

outreg2 [*] using T1,  keep(frac_stud_deseg )  dec(3)  nocons nor2 replace




***indices***
use teachers_8state, clear
qui areg lblackteach frac_stud_deseg   i.year , abs(distcode) cluster(distcode)
keep if e(sample)==1

areg lblackteach exp_index   i.year, abs(distcode) cluster(distcode)
est sto isco_index

areg lblackteach dis_index    i.year, abs(distcode) cluster(distcode)
est sto dis_index

tabstat exp_index  dis_index, by(year)

outreg2 [*] using T1,  keep(exp_index  dis_index )  dec(3)  nocons nor2 replace


 

*Figure A1: heterogeneity
*A: by initial black student share
use teachers_8state, clear	
xtile qtile64= frac_stud_black if year==1964, n(5)
bysort distcode: egen qtile=mean(qtile64)

sum frac_stud_black if year==1964 & qtile==1
sum frac_stud_black if year==1964 & qtile==5

matrix res=[.,.,.]
foreach n of numlist 1/5 {
areg lblackteach frac_stud_deseg    frac_stud_black i.year if qtile==`n', abs(distcode)
matrix res=[res \ `n',_b[frac_stud_deseg], _se[frac_stud_deseg]]
}

svmat res
replace res2=abs(res2)
g min=res2-res3*1.67
g max=res2+res3*1.67

twoway connect res2 res1, lpattern(solid) lcolor(black)  mcolor(black) msymbol(square)  ///
|| rcap min max res1,  lcolor(gs8) lwidth(thin) ///
legend(off) subtitle(A: Treatment Effects by Pre-Integration Black Student Share) xtitle(Quintile of 1964 Black Student Share) ytitle("Treatment Effect Magnitude (abs. value)") ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) saving(3a, replace) 


*B: by district size
use teachers_8state, clear	
xtile qtile64= stud_cnt if year==1964, n(5)
bysort distcode: egen qtile=mean(qtile64)

sum stud_cnt if year==1964 & qtile==1
sum stud_cnt if year==1964 & qtile==5

matrix res=[.,.,.]
foreach n of numlist 1/5 {
di `n'
areg lblackteach frac_stud_deseg    frac_stud_black i.year if qtile==`n', abs(distcode)
matrix res=[res \ `n',_b[frac_stud_deseg], _se[frac_stud_deseg]]
}
svmat res
replace res2=abs(res2)
g min=res2-res3*1.67
g max=res2+res3*1.67

twoway connect res2 res1, lpattern(solid) lcolor(black)  mcolor(black) msymbol(square) ///
|| rcap min max res1,  lcolor(gs8) lwidth(thin) ///
legend(off) subtitle(B: Treatment Effects by Pre-Integration District Size) xtitle(Quintile of 1964 Student Count) ytitle("Treatment Effect Magnitude (abs. value)") ///
graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white)) saving(3b, replace)


graph combine 3a.gph 3b.gph, xcommon ycommon rows(2) xsize(7) ysize(12) title(Figure A1: Treatment Effect Heterogeneity) graphregion(ifcolor(white) fcolor(white) lcolor(white) icolor(white))





